﻿using System;
using System.IO;
using Devv.Core.Utils;
using Devv.Support.Client;

namespace Devv.FreshTracker
{
	public class App
	{
		#region Events

		public delegate void EmptyEventHandler();
		public delegate void StringEventHandler(String message);
		public static event EmptyEventHandler OnFirstExecution;

		#endregion

		#region Constants

		public static String DONATE_URL = "http://devv.com/Donate.aspx?appFreshTracker";

		#endregion

		#region License

		private static License.Info LicenseInfo { get; set; }

		public static String LicensedTo
		{
			get
			{
				if (LicenseInfo == null)
				{
					return String.Empty;
				}

				return LicenseInfo.Email;
			}
		}

		#endregion

		#region Internal path properties

		public static String BasePath { get; set; }

		public static String DataPath
		{
			get { return BasePath + "Data/"; }
		}

		#endregion

		#region Init methods

		public static void Init(String path)
		{
			if (!Directory.Exists(DataPath))
			{
				Maintenance.Log("First execution.");

				Directory.CreateDirectory(DataPath);
				OnFirstExecution();
			}

			BasePath = Path.GetDirectoryName(path) + "/";
			
			Core.Erroo.Config.LoadFromXml();
			Core.Erroo.Config.LogPath = DataPath + "/ErrorLogs/";

			LicenseInfo = License.Init(ConfigUtil.GetConfig("Devv.AppName"));

			Options.Load();
			LocalCache.Load();
			SessionTimer.Load();
			AutoTracking.Load();
		}

		#endregion
	}
}